/**
 * 课程详情
 */

require('../css/courseDetail.less')
require("../fonts/iconfont.css")
document.ready(function () {


  // 返回功能
  const iconBack = document.querySelector(".iconleftarrow")
  iconBack.addEventListener("click", function () {
    window.history.back()
  })
  // 获取dom元素节点
  const posterImg = document.querySelector("#posterImg") //图片
  const titName = document.querySelector("#titName") //标题
  const calorie = document.querySelector("#calorie") //卡路里
  const times = document.querySelector("#time") //分钟
  const desc = document.querySelector("#desc") //练习标语
  const frequency = document.querySelector("#frequency") //练习平次
  const type = document.querySelector("#type") //器械
  const peopleNum = document.querySelector("#peopleNum") //人数

  /* 获取当前课程的id */
  let courseId = location.search.split('=')[1]
  /* 发送ajax 获取详情数据 */
  function getCourseDetail() {
    window.$http.get(`sports/courseDetail?id=${courseId}`, function (res) {
      if (res.status === 0) {
        console.log(res.data);
        titName.textContent = res.data.name;
        calorie.textContent = res.data.calorie;
        desc.textContent = res.data.desc;
        frequency.textContent = res.data.frequency;
        peopleNum.textContent = res.data.peoplenum;
        times.textContent = res.data.time;
        type.textContent = res.data.instrument;
        posterImg.src = 'http://139.9.177.51:8099' + res.data.imgurl;
        // 把播放器需要的数据存入本地
        window.localStorage.setItem('fragments', JSON.stringify(res.data.fragments))
      }
    })
  }
  /* 开始训练 */
  const startBtn = document.querySelector('#startBtn')
  startBtn.addEventListener('click', function () {
    location.href = `./player.html?id=${courseId}`
  })
  getCourseDetail()
})